package org.go.scheduler;

import java.text.ParseException;
import java.util.concurrent.ConcurrentHashMap;

import org.go.expcetion.GoException;
import org.go.expcetion.JobPersistenceException;
import org.go.expcetion.SchedulerException;
import org.go.trigger.Calendar;
import org.go.trigger.Trigger;
import org.go.trigger.TriggerKey;
import org.go.work.Work;
import org.go.work.WorkKey;

/**
 * 
 * @author hejie
 *
 */
public interface Scheduler {
	/**
	 * Add (register) the given <code>Calendar</code> to the Scheduler.
	 * 
	 * @param updateTriggers whether or not to update existing triggers that
	 * referenced the already existing calendar so that they are 'correct'
	 * based on the new trigger. 
	 * 
	 *  
	 * @throws SchedulerException
	 *           if there is an internal Scheduler error, or a Calendar with
	 *           the same name already exists, and <code>replace</code> is
	 *           <code>false</code>.
	 */
	void addCalendar(String calName, Calendar calendar, boolean replace, boolean updateTriggers) throws SchedulerException;

	/**
	 * 
	 * @return
	 */
	ConcurrentHashMap<String, Object> getContext() throws SchedulerException;

	/**
	 * 
	 * @return
	 */
	String getJobGroupNames() throws SchedulerException;

	/**
	 * 
	 * @return
	 */
	SchedulerResources getResource() throws SchedulerException;

	/**
	 * 
	 * @return
	 * @throws SchedulerException
	 */
	String getSchedulerName() throws SchedulerException;

	/**
	 * 
	 * @param tKey
	 * @return
	 */
	Trigger getTrigger(TriggerKey tKey) throws SchedulerException;

	/**
	 * 
	 * @return
	 * @throws SchedulerException
	 */
	boolean isShutdown() throws SchedulerException;

	/**
	 * 
	 * @param string
	 * @param se
	 */
	void notifySchedulerListenersError(String string, GoException se) throws SchedulerException;

	/**
	 * 
	 * @param string
	 * @param se
	 */
	void notifySchedulerListenersError(String string, JobPersistenceException se) throws SchedulerException;

	/**
	 * Pause the <code>{@link org.go.Go}</code> with the given
	 * key - by pausing all of its current <code>Trigger</code>s.
	 * 
	 * @see #resumeJob(WorkKey)
	 */
	void pauseWork(WorkKey workKey) throws SchedulerException;

	/**
	 * 
	 * @throws SchedulerException
	 */
	void pauseAllWorks() throws SchedulerException;

	/**
	 * 
	 * @param cron
	 * @param task
	 * @throws ParseException
	 */
	//void schedule(String cron, Go task) throws Exception;

	/**
	 * 
	 * @param cron
	 * @param task
	 * @throws ParseException
	 */
	//void schedule(Work work, Trigger trigger) throws GoException;

	/**
	 * 
	 * @throws GoException
	 */
	//void start() throws GoException;;

	/**
	 * 
	 * @param seconds
	 * @throws GoException
	 */
	//void startDelayed(int seconds) throws SchedulerException;

	/**
	 * 
	 * @param cron
	 * @param task
	 * @throws ParseException
	 */
	void scheduler(Work work, Trigger trigger) throws SchedulerException;

	/**
	 * Halts the <code>Scheduler</code>'s firing of <code>{@link Trigger}s</code>,
	 * and cleans up all resources associated with the Scheduler. Equivalent to
	 * <code>shutdown(false)</code>.
	 * 
	 * <p>
	 * The scheduler cannot be re-started.
	 * </p>
	 * 
	 * @see #shutdown(boolean)
	 */
	//void shutdown() throws SchedulerException;

	/**
	 * 
	 * @param waitForJobsToComplete
	 * @throws SchedulerException
	 */
	void shutdown(boolean waitForWorksToComplete) throws SchedulerException;

	/**
	 * 
	 * @throws SchedulerException
	 */
	void shutdownNow() throws SchedulerException;

	/**
	 * 
	 * @param tKey
	 */
	void unscheduleWork(TriggerKey tKey) throws SchedulerException;

	/**
	 * 
	 * @return
	 */
	String getVersion();
}
